package com.examination.client.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.examination.client.annotation.PassToken;
import com.examination.client.domian.dto.*;
import com.examination.client.domian.vo.*;
import com.examination.client.entity.CourierInfo;
import com.examination.client.service.ICourierInfoService;
import com.examination.client.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 快递信息入库表 前端控制器
 * </p>
 *
 * @author xiaodong
 * @since 2021-10-17
 */


@RestController
@Api(tags = "快递入库管理")
@RequestMapping("/courier")
@CrossOrigin(origins = "*")
public class CourierInfoController {

    @Resource
    ICourierInfoService courierInfoService;


    @PostMapping("/save")
    @ApiOperation("扫码入库(保存入库信息)")
    public Result<CourierInfo> save(@RequestBody @Validated CourierInfoDTO courierInfoDTO) throws Exception  {
        return Result.success(courierInfoService.save(courierInfoDTO));
    }

    @PostMapping("/save/subsite")
    @ApiOperation("扫码入库(保存入库信息)-主子账号同时入库")
    public Result<CourierInfo> saveSubsite(@RequestBody @Validated CourierInfoDTO courierInfoDTO) throws Exception  {
        return Result.success(courierInfoService.saveSubsite(courierInfoDTO));
    }


    @GetMapping("/storage/status")
    @ApiOperation("查询入库状态")
    public Result<Boolean> storageStatus(@RequestParam(value = "code") String code) throws Exception  {
        return Result.success(courierInfoService.storageStatus(code));
    }


    @PostMapping("/delivery")
    @ApiOperation("扫码出库")
    public Result<CourierInfo> delivery(@RequestBody @Validated CourierInfoDTO courierInfoDTO)throws Exception {
        return Result.success(courierInfoService.delivery(courierInfoDTO));
    }



    @PostMapping("/delete)")
    @ApiOperation("撤销(删除)")
    public Result<Boolean> delete(@RequestParam(value = "id") String id,@RequestParam(value = "type") Integer type) {
        return Result.success(courierInfoService.delete(id,type));
    }

    @GetMapping("/statistics")
    @ApiOperation("首页数量统计")
    public Result<TodayStatisticsVO> statistics(TodayStatisticsQueryDTO todayStatisticsQueryDTO) {
        return Result.success(courierInfoService.statistics(todayStatisticsQueryDTO));
    }


    @GetMapping("/scan/statistics")
    @ApiOperation("扫码页面数量统计")
    public Result<ScanStatisticsVO> scanStatistics(ScanStatisticsDTO scanStatisticsDTO) {
        return Result.success(courierInfoService.scanStatistics(scanStatisticsDTO));
    }


    @GetMapping("today/site/statistics")
    @ApiOperation("站点快递数量列表统计")
    public Result<List<TodaySiteStatisticsVO>> siteCourierList(TodayStatisticsQueryDTO todayStatisticsQueryDTO) {
        return Result.success(courierInfoService.siteCourierList(todayStatisticsQueryDTO));
    }

    @GetMapping("today/site/statistics/storage")
    @ApiOperation("今日待入库")
    public Result<TodaySiteStorageStatisticsVO> todaySiteStorageStatistics() {
        return Result.success(courierInfoService.todaySiteStorageStatistics());
    }

    @GetMapping("today/site/statistics/1")
    @ApiOperation("站点快递数量列表统计")
    public Result<List<CourierSiteInfoDTO>> siteCourierList1(TodayStatisticsQueryDTO todayStatisticsQueryDTO) {
        return Result.success(courierInfoService.siteCourierList1(todayStatisticsQueryDTO));
    }

    @PostMapping("/batch/delivery")
    @ApiOperation("出库/入库(支持批量操作)")
    public Result<Boolean> batchDelivery(@RequestBody @Validated DeliveryDTO deliveryDTO) {
        return Result.success(courierInfoService.batchDelivery(deliveryDTO));
    }

    @PostMapping("/batch/save/main")
    @ApiOperation("主账号批量入库")
    public Result<Boolean> batchSaveMain(@RequestBody @Validated DeliveryDTO deliveryDTO) {
        return Result.success(courierInfoService.batchSaveMain(deliveryDTO));
    }

    @PostMapping("/batch/save/child")
    @ApiOperation("子账号批量入库")
    public Result<List<String>> batchSaveSub(@RequestBody @Validated BatchDeliveryDTO batchDeliveryDTO) {
        return Result.success(courierInfoService.batchSaveChild(batchDeliveryDTO));
    }

    @PutMapping("/modify")
    @ApiOperation("修改入库信息")
    public Result<Boolean> modify(@RequestBody @Validated CourierInfoDTO courierInfoDTO) {
        return Result.success(courierInfoService.modify(courierInfoDTO));
    }

    @PutMapping("/modify/phone")
    @ApiOperation("修改入库信息")
    public Result<Boolean> modifyPhone(@RequestBody @Validated CourierInfoDTO courierInfoDTO) {
        return Result.success(courierInfoService.modifyPhone(courierInfoDTO));
    }

    @PassToken
    @GetMapping("/detail")
    @ApiOperation("快递入库信息详情")
    public Result<CourierInfoDetailVO> detail(@RequestParam("id") String id) throws Exception {
        return Result.success(courierInfoService.detail(id));
    }

    @PassToken
    @GetMapping("/info")
    @ApiOperation("快递信息")
    public Result<DeliveryInfoVO> info(@RequestParam("courierCode") String courierCode) throws Exception {
        return Result.success(courierInfoService.info(courierCode));
    }


    @GetMapping("/scan/info")
    @ApiOperation("扫码查询快递信息")
    public Result<ScanInfoVO> scanInfo(@RequestParam("courierCode") String courierCode,
                                       @RequestParam(value = "nextSiteId",required = false) Integer nextSiteId) throws Exception {
        return Result.success(courierInfoService.scanInfo(courierCode,nextSiteId));
    }

    @GetMapping("/abnormal/list")
    @ApiOperation("查询异常快递信息列表")
    public Result<Page<CourierInfo>> abnormalList(StatisticsQueryDTO statisticsQueryDTO) throws Exception {
        return Result.success(courierInfoService.abnormalList(statisticsQueryDTO));
    }

    @GetMapping("/abnormal/excel")
    @ApiOperation("异常快递信息列表导出")
    public void abnormalExcel(StatisticsQueryDTO statisticsQueryDTO,HttpServletResponse response) throws Exception {
        courierInfoService.abnormalExcel(statisticsQueryDTO,response);

    }

    @GetMapping("/list")
    @ApiOperation("查询快递信息列表")
    public Result<Page<CourierInfoDetailVO>> list(CourierInfoListQueryDTO courierInfoListQueryDTO) throws Exception {
        return Result.success(courierInfoService.list(courierInfoListQueryDTO));
    }

    @GetMapping("/message/list")
    @ApiOperation("查询快递是否通知信息列表")
    public Result<List<CourierInfo>> messageList(CourierInfoListQueryDTO courierInfoListQueryDTO) throws Exception {
        return Result.success(courierInfoService.messageList(courierInfoListQueryDTO));
    }

    @ApiOperation("app导出")
    @GetMapping("/getExcel")
    public void getExcel(HttpServletResponse response) throws Exception {
        courierInfoService.getExcel(response);
    }

    @ApiOperation("后台统计(统计对账)")
    @GetMapping("/statistics/reconciliation")
    public Result<QueryStatisticsVO> statisticsReconciliation(StatisticsQueryDTO statisticsQueryDTO) throws Exception {
        QueryStatisticsVO queryStatisticsVO = courierInfoService.statisticsReconciliation(statisticsQueryDTO);
        return Result.success(queryStatisticsVO);
    }

    @PassToken
    @ApiOperation("后台导出(统计对账)")
    @GetMapping("/statistics/excel")
    public void statisticsExcel(StatisticsQueryDTO statisticsQueryDTO,HttpServletResponse response) throws Exception {
         courierInfoService.statisticsExcel(statisticsQueryDTO,response);

    }

    @PassToken
    @GetMapping("/my/list")
    @ApiOperation("查询我的快递列表")
    public Result<Page<CourierInfoDetailVO>> myList(QueryCourierListDTO QueryCourierListDTO) throws Exception {
        return Result.success(courierInfoService.myList(QueryCourierListDTO));
    }

    @PassToken
    @GetMapping("/my/num")
    @ApiOperation("查询我的快递数量")
    public Result<Integer> myNum(QueryCourierListDTO QueryCourierListDTO) throws Exception {
        return Result.success(courierInfoService.myNum(QueryCourierListDTO));
    }
    
    @GetMapping("/hidden/phone")
    @ApiOperation("隐藏号码匹配真实号码列表")
    public Result<List<HiddenPhoneVO>> hiddenPhoneList(HiddenPhoneQueryDTO hiddenPhoneQueryDTO) throws Exception {
        return Result.success(courierInfoService.hiddenPhoneList(hiddenPhoneQueryDTO));
    }

}

